﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;

namespace Tts_Test
{
    class Program
    {
        static void Main(string[] args)
        {

            byte[] data = new byte[1024];
            IPAddress ip = IPAddress.Parse("127.0.0.1");
            IPEndPoint ipEnd = new IPEndPoint(ip, 8501);
            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            try
            {
                socket.Connect(ipEnd);
            }
            catch (SocketException e)
            {
                Console.WriteLine("Fail to connect server");
                Console.WriteLine(e.ToString());
                Console.ReadKey(true);
                return;
            }
            //默认  vixy
            socket.Send(Encoding.UTF8.GetBytes("前方，200米，有违章拍照，请减速慢行。&voice_name = vixy,speed = 50,volume = 50&05100510.voc&"));
            while (true)
            {
                data = new byte[1024];
                socket.Receive(data);
                string  stringData = Encoding.UTF8.GetString(data);
                if (!string.IsNullOrWhiteSpace(stringData))
                {
                    Console.Write(stringData);
                    break;
                }
            }
            Console.WriteLine("disconnect from server");
            socket.Shutdown(SocketShutdown.Both);
            socket.Close();
            Console.ReadKey();
        }
    }
}
